package com.cetccloud.ap.config;

import org.apache.kafka.clients.admin.AdminClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.kafka.core.KafkaAdmin;

/**
 * @ClassName KafkaConfig
 * @Description TODO
 * @Author superz
 * @Date 2021/4/20 9:40
 * @Version 1.0
 **/
@Configuration
public class KafkaConfig {

    @Autowired
    private KafkaAdmin kafkaAdmin;

    @Bean
    public AdminClient adminClient() {
        return AdminClient.create(kafkaAdmin.getConfigurationProperties());
    }

    /*@Bean
    public NewTopic initialTopic(@Autowired AdminClient adminClient) {
        NewTopic topic = new NewTopic("testtopic",3, (short) 2);
        adminClient.createTopics(Arrays.asList(topic));

        try {
            ListTopicsResult listTopics = adminClient.listTopics();
            Set<String> topics = listTopics.names().get();
            for (String _topic : topics) {
                System.err.println(_topic);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return topic;
    }*/

    /**
     * 创建TopicName为testtopic1的Topic并设置分区数为3以及副本数为2
     **/
    /*@Bean
    public NewTopic initialTopic1() {
        return new NewTopic("testtopic1",3, (short) 2);
    }*/

}
